import allure
from appium.webdriver.common.mobileby import MobileBy


def decorator(decorator_find):
    blacklist = ['//*[@resource-id="com.xueqiu.android:id/iv_close"]']
    def wrapper(*args ,**kwargs):
        instance = args[0]  # *args包含三个元素，取第一个，这里的instance相当于self
        try:
            return decorator_find(*args, **kwargs)
        except Exception:
            allure.attach.file(instance.screenshot(),name='弹框截图', attachment_type=allure.attachment_type.PNG)
            for ele_xpath in blacklist:
                eles = instance.finds(MobileBy.XPATH, ele_xpath)
                if len(eles) > 0:
                    eles[0].click()
                    return decorator_find(*args, **kwargs)
    return wrapper